import request from '../utils/request.js'

// 获取商品列表
export const GoodsListApi = (data) => {
  return request.get('/goods', {
    params: data
  })
}

// 获取商品分类列表
export const GetGoodListApi = () => {
  return request.get('/categories')
}

export const GetGoodListApi1 = () => {
  return request.get('/categories', {
    params: {
      type: 2
    }
  })
}

// 获取商品分类列表--2
export const GoodsortlistApi = (data) => {
  return request.get('/categories', {
    params: data
  })
}

// 删除商品
export const delGoodsApi = (id) => {
  return request.delete(`/goods/${id}`)
}

// 获取-商品参数和属性[many/only]
export const goodsprop = (id, sel) => {
  return request.get(`/categories/${id}/attributes`, {
    params: {
      sel
    }
  })
}
// 添加商品
export const addgoods = (data, attrs) => {
  return request.post('/goods', {
    goods_name: data.goods_name,
    goods_price: data.goods_price,
    goods_weight: data.goods_weight,
    goods_number: data.goods_number,
    goods_cat: data.goods_cat,
    goods_introduce: data.goods_introduce,
    pics: [],
    attrs

  })
}
// 添加分类
export const addpropApi = (catname, catlevel, catpid) => {
  request.post('categories', {
    cat_name: catname,
    cat_level: catlevel || 0,
    cat_pid: catpid || 0
  })
}

// 编辑提交商品
export const editpropApi = (id, attrId, attrname, attrsel, attrvals) => {
  request.put(`categories/${id}/attributes/${attrId}`, {
    attr_name: attrname,
    attr_sel: attrsel,
    attr_vals: attrvals
  })
}

// 添加分类
export const addfenleiApi = (catpid, catname) => {
  request.post('categories', {
    cat_pid: catpid,
    cat_name: catname
  })
}

// 添加商品动态参数/静态属性
export const addparams = (id, attrName, attrsel) => {
  return request.post(`/categories/${id}/attributes`, {
    attr_name: attrName,
    attr_sel: attrsel
  })
}
